# -*- coding: utf-8 -*-
# @Time    : 2019/11/4 14:19
# @Author  : LiHaowen
# @Email   : lihaowen2017@163.com
# @File    : yield_from_test.py

# python3.3新加yield from 语法
from itertools import chain  # 将迭代类型连接起来做一个for循环

my_list = [1, 2, 3]
my_dict = {
    "bobby1": "http://projectsedu.com",
    "bobby2": "http://www.imooc.com",
}


# yield from iterable
def my_chain(*args, **kwargs):
    # 生成器实际使用案例，将多个迭代类型连接起来做一个for循环
    for my_iterable in args:
        yield from my_iterable  # 将iterable中对象逐个yield出来
        # for value in my_iterable:
        #     yield value


# for value in my_chain(my_list, my_dict, range(5, 10)):
#     print(value)


# def g1(iterable):
#     yield iterable
#
#
# def g2(iterable):
#     yield from iterable
#
#
# for value in g1(range(10)):
#     print(value)
#
# for value in g2(range(10)):
#     print(value)


def g1(gen):
    yield from gen


def main():
    # 调用方
    g = g1()
    g.send(None)


# 1. main 调用方 g1(委托生成器) gen子生成器
# 1. yield from 会在调用方与子生成器之间建立一个双向通道

